package com.sunop.panticommon.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MqConfirmCallback implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnsCallback {
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (ack) {
            log.info("Message confirmed: {}", correlationData.getId());
        } else {
            log.error("Message failed: {}", cause);
        }
    }

    @Override
    public void returnedMessage(ReturnedMessage returned) {
        log.error("Message routing failed: {}", returned.getMessage());
    }
}